//
// File: OyFreeCameraMode.cpp
//

#include "OyFreeCameraMode.h"

OyCameraModeFree::OyCameraModeFree(void)
{
	OyMovementController::Init();
}


OyCameraModeFree::~OyCameraModeFree(void)
{
}

void OyCameraModeFree::SetRotation(float rx, float ry, float rz)
{
	m_fRotX = rx;
	m_fRotY = ry;
	m_fRotZ = rz;

	RecalcAxes();
}

void OyCameraModeFree::AddRotationSpeed(float sx, float sy, float sz)
{ 
	m_fPitchSpeed += sx; 
	m_fYawSpeed   += sy;
	m_fRollSpeed  += sz;
}

void OyCameraModeFree::SetRotationSpeed(float sx, float sy, float sz)
{ 
	m_fPitchSpeed = sx; 
	m_fYawSpeed   = sy;
	m_fRollSpeed  = sz;
}

void OyCameraModeFree::Update(float fElapsedTime)
{
	// add rotation speed
	m_fRotX = (m_fPitchSpeed * fElapsedTime);
	m_fRotY = (m_fYawSpeed   * fElapsedTime);
	m_fRotZ = (m_fRollSpeed  * fElapsedTime);

	// recalculate axes
	RecalcAxes();

	// calculate velocity vector
	m_vcVelocity.x = m_vcDir.x * m_fThrust * fElapsedTime;
	m_vcVelocity.y = m_vcDir.y * m_fThrust * fElapsedTime;
	m_vcVelocity.z = m_vcDir.z * m_fThrust * fElapsedTime;

	// move position according to velocity vector
	m_vcPos.x += m_vcVelocity.x;
	m_vcPos.y += m_vcVelocity.y;
	m_vcPos.z += m_vcVelocity.z;
}